import { test } from "node:test"; import assert from "node:assert/strict"; import { clamp } from "../src/clamp.js"; test("clamp returns the same value when within bounds", () => { assert.strictEqual(clamp(5, 0, 10), 5); assert.strictEqual(clamp(0, -5, 5), 0); }); test("clamp returns lower bound when value is below it", () => { assert.strictEqual(clamp(-10, -5, 5), -5); assert.strictEqual(clamp(2, 3, 8), 3); }); test("clamp returns upper bound when value is above it", () => { assert.strictEqual(clamp(20, 0, 10), 10); assert.strictEqual(clamp(9, 0, 5), 5); }); test("clamp returns undefined for non‑numeric inputs", () => { assert.strictEqual(clamp("a", 0, 1), undefined); assert.strictEqual(clamp(0, "b", 1), undefined); assert.strictEqual(clamp(0, 0, "c"), undefined); assert.strictEqual(clamp(NaN, 0, 1), undefined); assert.strictEqual(clamp(0, Infinity, 1), undefined); });